refactor(hash-aggr): route grouping sets to the migrated hash streams - #24870
Conversation
`GROUPING SETS` / `CUBE` / `ROLLUP` still fell back to the legacy `GroupedHashAggregateStream`, because the migrated partial and single stream predicates required a plain `GROUP BY`. Grouping sets are always planned with `InputOrderMode::Linear` since apache#24422, and the shared `AggregateHashTable` already expands every grouping set of an input batch, so they can run on `PartialHashAggregateStream` and `SingleHashAggregateStream`. - Move `init_empty_grouping_sets` from the partial table into the shared table, so single aggregation also emits the grand-total group on empty input. - Drop the `is_single()` condition from the partial and single stream predicates. The final and partial-reduce predicates keep it, because state-input stages must receive the expanded keys as a plain group by. - The spill-mode `check_grouping_sets` snapshot changes because the migrated partial stream flushes after every batch under memory pressure; the final results are unchanged. Part of apache#22710 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
| | 3 | | 1 | 1 | | ||
| | 3 | | 1 | 2 | | ||
| | 3 | 2.0 | 0 | 2 | | ||
| | 3 | 2.0 | 0 | 1 | |
There was a problem hiding this comment.
Both are valid outputs for partial aggregation with early emit; the difference is because execution is not 100% the same between the legacy and refactored implementations.
There was a problem hiding this comment.
just wondering in case of distinct and regular aggregation, usually dedup should be on the partial stage?
There was a problem hiding this comment.
Yes, if there are enough memory for all groups, it must be fully deduplicated.
This test result with duplicates is the outcome of aggregate->OOM->early emit -> aggregate -> OOM -> early emit -> ... repeatations.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24870 +/- ##
==========================================
- Coverage 81.61% 81.61% -0.01%
==========================================
Files 1123 1123
Lines 409562 409634 +72
Branches 409562 409634 +72
==========================================
+ Hits 334284 334341 +57
- Misses 55647 55655 +8
- Partials 19631 19638 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Which issue does this PR close?
Part of #22710
Rationale for this change
Let aggregate with grouping sets get route into the newly refactored aggregation (see above EPIC for backgrounds)
What changes are included in this PR?
The key change is at datafusion/physical-plan/src/aggregates/mod.rs, it changes the planning decision as described above
What is the testing strategy for this PR?
Existing tests.
Are there any user-facing changes?
No